package pers.bbw.crr.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import pers.bbw.crr.dao.ClubMapper;
import pers.bbw.crr.dto.ClubSearchDto;
import pers.bbw.crr.entity.Club;
import pers.bbw.crr.service.ClubService;

import javax.annotation.Resource;
import java.util.Date;

/**
 * clubService业务层处理
 *
 * @author bbw
 * @date 2024-12-13
 */
@Service
public class ClubServiceImpl implements ClubService {

    @Resource
    private ClubMapper clubMapper;

    /**
     * 查询club
     *
     * @param id club主键
     * @return club
     */
    @Override
    public Club selectClubById(int id) {
        return clubMapper.selectClubById(id);
    }

    /**
     * 查询club列表
     *
     * @param club club
     * @return club
     */
    @Override
    public PageInfo<Club> selectClubList(ClubSearchDto dto) {
        Club club = new Club();
        BeanUtil.copyProperties(dto, club);
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        PageInfo<Club> clubPageInfo = new PageInfo<>(clubMapper.selectClubList(club));
        return clubPageInfo;
    }

    /**
     * 新增club
     *
     * @param club club
     * @return 结果
     */
    @Override
    public int save(Club club) {
        club.setState(0); //新增社团默认为开放状态
        return clubMapper.insertClub(club);
    }

    /**
     * 修改club
     *
     * @param club club
     * @return 结果
     */
    @Override
    public void updateClub(Club club) {
        club.setUpdateTime(new Date());
        clubMapper.updateClub(club);
    }

    /**
     * 批量删除club
     *
     * @param ids 需要删除的club主键
     * @return 结果
     */
    @Override
    public int deleteClubByIds(int[] ids) {
        return clubMapper.deleteClubByIds(ids);
    }

    /**
     * 删除club信息
     *
     * @param id club主键
     * @return 结果
     */
    @Override
    public int deleteClubById(int id) {
        return clubMapper.deleteClubById(id);
    }

}
